﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 合并页面
{
    // 摘要:
    //     提供对INI文件的操作。
    public static class IniFile
    {
        [System.Runtime.InteropServices.DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);

        /// <summary>
        /// 根据ini文件路径，节，关键词得到相应的值。[filepath] readpath="E:\TAOBAO\taobao"
        /// </summary>
        /// <param name="section">INI文件的节点</param>
        /// <param name="key">该节点下的关键词</param>
        /// <param name="iniFile">INI文件的路径</param>
        /// <returns>返回INI文件中该节点下KEY的值。</returns>
        public static string GetKeyValue(string section,string key,string iniFile)
        {
            StringBuilder fileReadPath = new StringBuilder(200);
            string ret = "";
            GetPrivateProfileString(section, key,ret, fileReadPath, 200, System.Windows.Forms.Application.StartupPath + "\\" + iniFile);
            if (fileReadPath.Length != 0)
            {
                ret = fileReadPath.ToString();
            }  
            return ret;
        }
    }
}
